#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef pair < int , int > pii;
typedef vector < int > vec;
typedef vector < pii > veg;
typedef long long ll;
typedef double db;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch =='-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;
const int L = 455;
const int mod = 1e9 + 7;

int pri[L],pnum,a[N],n,Q;
char st[92][18][N];
bool v[L];
int rt[N],ind[N],pre[N],lst[N],lg[N],ans;

void shai(int l) {
    for(int i = 2;i <= l;i++) {
	if(!v[i]) pri[++pnum] = i;
	for(int j = 1;j <= pnum && pri[j] * i <= l;j++) {
	    v[pri[j] * i] = true;
	    if(i % pri[j] == 0) break;
	}
    }
}

namespace seg {
    const int N = 1e7 + 10;
    int val[N],ch[N][2],ndn;
    void build(int &o,int l = 1,int r = n) {
	o = ++ndn; if(l == r) return val[o] = ind[l],void(); int mid = l + r >> 1;
	build(ch[o][0],l,mid); build(ch[o][1],mid + 1,r); val[o] = 1ll * val[ch[o][0]] * val[ch[o][1]] % mod;
    }
    void upd(int y,int &x,int pos,int v,int l = 1,int r = n) {
	x = ++ndn; val[x] = 1ll * val[y] * v % mod; ch[x][0] = ch[y][0]; ch[x][1] = ch[y][1]; if(l == r) return; int mid = l + r >> 1;
	if(pos <= mid) upd(ch[y][0],ch[x][0],pos,v,l,mid); else upd(ch[y][1],ch[x][1],pos,v,mid + 1,r);
    }
    int query(int xl,int xr,int x,int l = 1,int r = n) {
	if(xl == l && xr == r) return val[x]; int mid = l + r >> 1;
	if(xr <= mid) return query(xl,xr,ch[x][0],l,mid); else if(xl > mid) return query(xl,xr,ch[x][1],mid + 1,r);
	else return 1ll * query(xl,mid,ch[x][0],l,mid) * query(mid + 1,xr,ch[x][1],mid + 1,r) % mod; 
    }
}

int pw[20],ppr[92][25];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in; shai(L - 2);
    for(int i = 1;i <= n;i++) {
	a[i] = in;
	for(int j = 1;j <= pnum && a[i] > 1;j++) {
	    if(a[i] % pri[j] == 0)
		while(a[i] % pri[j] == 0) st[j][0][i]++,a[i] /= pri[j];
	}
    }
    for(int i = 2;i <= n;i++) lg[i] = lg[i >> 1] + 1;
    for(int i = (pw[0] = 1);i <= lg[n];i++) pw[i] = pw[i - 1] << 1;
    for(int i = 1;i <= pnum;i++)
	for(int k = 1;k <= lg[n];k++)
	    for(int j = 1;j + pw[k] - 1 <= n;j++)
		st[i][k][j] = max(st[i][k - 1][j],st[i][k - 1][j + pw[k - 1]]);
    for(int i = 1;i <= pnum;i++) for(int j = (ppr[i][0] = 1);j < 25;j++) ppr[i][j] = 1ll * ppr[i][j - 1] * pri[i] % mod;
    for(int i = 1;i <= n;i++) pre[i] = lst[a[i]], lst[a[i]] = i;
    for(int i = 1;i <= n;i++) if(pre[i] == 0) ind[i] = a[i]; else ind[i] = 1;
    for(int i = 1;i <= n;i++) lst[i] = 0;
    for(int i = 1;i <= n;i++) if(pre[i]) lst[pre[i]] = i;
    seg :: build(rt[0]);
    for(int i = 1;i <= n;i++) if(lst[i]) seg :: upd(rt[i - 1],rt[i],lst[i],a[lst[i]]); else rt[i] = rt[i - 1];
    Q = in;
    while(Q--) {
	int l = (in + ans) % n + 1,r = (in + ans) % n + 1; if(l > r) swap(l,r); int k = lg[r - l + 1]; ans = 1;
	for(int i = 1;i <= pnum;i++) {
	    int mx = max(st[i][k][l],st[i][k][r - pw[k] + 1]);
	    ans = 1ll * ans * ppr[i][mx] % mod;
	}
	ans = 1ll * ans * seg :: query(l,r,rt[l - 1]) % mod;
	printf("%d\n",ans);
    }
}
